(function($){
	/**
	 * 创建UUID
	 */
	function S4() {
		return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	}
	/**
	 * 生成windowId
	 */
	function  CreateIndentityWindowId(){
		var windowId = "UUID-"+(S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
		return windowId;
	}
	/**
	 * 销毁
	 */
	function destroy(target){
		var options = $(target).dialog("options");
		if(options.fck){
			$("body").children("iframe").remove();
			KE.remove(options.fck.id);
		}
		if(options.ke){
			KE.remove(options.ke.id);
		}
		$(target).destroy();
	}
	
	/**
	 * 获取当前操作的window 
	 *  @param target 当前窗口的windowId 或者 当前窗口中的元素(element)
	 */
	function getWindow(target){
		if(typeof target == "string"){
			return document.getElementById(target);
		}else{
			return $(target).parents(".window-body");
		}
	}
	
	//入口方法
	$.createWin = function(options){
		
		if(!options.url){
			return false;
		}
		var windowId = CreateIndentityWindowId();
		if(options.winId){
			windowId=options.winId;
		}
		options = $.extend({},$.createWin.defaults, options || {});
		var dialog  = $('<div id="'+windowId+'"></div>');
		var data = "<iframe ";
		data += " id='_DialogFrame_"+ windowId +"' allowTransparency='true'  width='100%' height='100%' frameborder='0' style=\"background-color: #transparent; border:none;\"></iframe>";
		$(dialog).html(data);
		dialog.appendTo('body');
		
		dialog.dialog(options);
		dialog.dialog('open');
		$.parser.parse(dialog);
		options.onComplete.call(this,windowId);
		 $('#_DialogFrame_' + windowId ).attr("src",options.url);
		
		return dialog;
	};
	
	//关闭并销毁实体
	$.fn.destroy =function(){
		this.dialog("destroy"); 
	};
	window.GETWIN = getWindow;
	window.destroy =destroy;
	
	//默认参数
	$.createWin.defaults = $.extend({},$.fn.dialog.defaults,{
			url:'',					//窗口要加载的html片段地址
			data:'',				//可带参数，data类型为jqurey.ajax的data参数类型
			zIndex: 100000,	
			iconCls:'icon-edit',
			height : 300,
			width :  400,
			collapsible: true,
			minimizable: false,
			maximizable: false,
			resizable:false,
			closable: true,
			modal:true,
			onClose:function(){
				$.fn.destroy;
			},
			onComplete:function(windowId){}	//创建成功后的回调方法		
	});
})(jQuery);

var curDialog;
function showWin(title,url,width,height){
	   var confing ={
		  url : url,
		  title : title,
		  width : width,
		  height : height,
		  maximizable : false
		};
	   curDialog = $.createWin(confing);	
}